package com.nuanshui.heatedloan.util;

import org.apache.shiro.SecurityUtils;

import com.nuanshui.heatedloan.entity.cms.security.User;
import com.nuanshui.heatedloan.extension.shiro.ShiroDbRealm.ShiroUser;

/**
 * Shiro 与用户相关工具类
 * 
 */
public class UserUtil {

	/**
	 * 取出Shiro中的当前用户Id.
	 */
	public static Long getCurrentUserId() {
		final ShiroUser user = (ShiroUser) SecurityUtils.getSubject()
				.getPrincipal();
		return user.getId();
	}

	/**
	 * 取出Shiro中的当前用户UserName
	 */
	public static String getCurrentLoginName() {
		final ShiroUser user = (ShiroUser) SecurityUtils.getSubject()
				.getPrincipal();
		return user.getLoginName();
	}

	/**
	 * 拿到当前用户对象
	 */
	public static User getCurrentUser() {
		final ShiroUser user = (ShiroUser) SecurityUtils.getSubject()
				.getPrincipal();
		return user.getUser();
	}

}
